package com.hyl.job;

import com.hyl.service.weixin.IOrderService;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.scheduling.annotation.Scheduled;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author hyl
 * @description超时关单
 * @create 2025-06-07 11:32
 */
@Slf4j
public class TimeoutCloseOrderJob {


    @Resource
    private IOrderService orderService;

    @Scheduled(cron = "0 0/10 * * * ?")
    public void exec(){
       try {
           log.info("超过30分钟自动关闭订单");
           List<String> orderList = orderService.queryTimeoutCloseOrderList();
           if (orderList == null||orderList.isEmpty()){
               log.info("没有超时订单");
               return;
           }
           for (String orderId:orderList){
               boolean statues = orderService.changeOrderClose(orderId);
               log.info("关闭订单{}",statues? "成功":"失败");
           }
       } catch (Exception e){
           log.info("超时关闭订单失败");
       }

    }


}
